#ifndef __HUFFMAN__
#define __HUFFMAN__

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "debug.h"

#define BYTES 256
#define HUFFMAN_SHORT

#ifdef HUFFMAN_SHORT

typedef struct NODE_T {
	struct NODE_T *left, *right;
	int freq;
	short c;
} *NODE;

typedef struct SAVE_HUFFMAN_FREQUENCY_{
	int max;
	int lenght;
	int *freq;
} FREQUENCY_SAVE;

NODE newNodeShortHuffmanTree(int freq, short c, NODE a, NODE b);

void qInsertShortHuffmanTree(NODE n);

NODE qRemoveShortHuffmanTree();

void buildCodeShortHuffmanTree(NODE n, char *s, int len);

int initShortHuffmanTree(const short *s,int size);

void encode(const char *s, char *out);

NODE decode(const char *s);

void saveHuffmanFrequency(FILE *save);
void readHuffmanFrequency(FILE *load,FREQUENCY_SAVE saves);

#else

typedef struct NODE_T {
	struct NODE_T *left, *right;
	int freq;
	char c;
} *NODE;

NODE newNode(int freq, char c, NODE a, NODE b);

void qInsert(NODE n);

NODE qRemove();

void buildCode(NODE n, char *s, int len);

void init(const char *s);

void encode(const char *s, char *out);

void decode(const char *s, NODE t);

#endif






#endif
